﻿@model viBook.Models.User
@{
    var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
}
<script type="text/javascript">
    
    $("#file_upload").uploadify({
            'uploader': '/Scripts/uploadify/uploadify.swf',
            'script': '@Url.Action("UploadAvatar", new {AUTHID = cookie.Value})',
            'fileDataName': 'FileData',
            'buttonText': 'Select Image',
            'multi': false,
            'width': 120,
            'sizeLimit': 700000,
            'simUploadLimit': 1,
            'cancelImg': '/Scripts/uploadify/cancel.png',
            'folder': '/Images/Avatar',
            'fileExt': '*.jpg;*.png;*.gif',
            'fileDesc': 'Web Image Files (.JPG, .GIF, .PNG)',
            'removeCompleted': false,
            'onError': function (event, ID, fileObj, errorObj) {
                /*if (d.status == 404)
                    alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
                else if (d.type === "HTTP")
                    alert("error " + d.type + ": " + d.status);
                else if (d.type === "File Size")
                    alert(c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB");
                else*/
                alert("error " + errorObj.type + ": " + errorObj.info);
            },
            'onComplete': function (event, queueId, fileObj, response, data) {
                response = $.parseJSON(response);
                $("#filesUploaded").val(fileObj.filePath);
                if (response.Success) {
                    $("#avatar_img").attr("src", response.AvatarUrl);
                    $("#avatar_icon").attr("src", response.AvatarUrl);
                }
                else {
                    alert(response.Message);
                }

            }

        });
</script>